<?php
class Application_Model_DbTable_Comment extends Zend_Db_Table_Abstract{
	protected $_name = 'comments';
	
	public function fetchAllWithAuthor($post){
		$select = $this->select();
		$select->setIntegrityCheck(false);
	
		$select	->from(array('n'=>$this->_name))
				->joinLeft(array('e'=>'etudiant'), 'n.author=e.etudiant_id', array('pseudo'))
				->where('post = ?', $post);
		return $select->query()->fetchAll(PDO::FETCH_OBJ);
	}
	public function findWithAuthor($id){
		$select=$this->select();
		$select->setIntegrityCheck(false);
		
		$select ->from(array('n'=>$this->_name))
				->joinLeft(array('e'=>'etudiant'), 'n.author=e.etudiant_id', array('pseudo'))
				->where('id = ?',$id);
		return $select->query()->fetch(PDO::FETCH_OBJ);
	}
	public function deleteCommentByPost($id){
		$where = $this->getAdapter()->quoteInto('post = ?', $id);
		return parent::delete($where);
	}
}